package band.wukong.practice.javase.core.thread.status;

/**
 * Desc: 死亡状态。线程运行时因抛出RuntimeException异常而结束，此时主线程继续正常运行至结束
 * Author: sunjs
 * Date: 2009-11-5 10:58:15
 */
public class DeadWithException extends Thread {
    public void run() {
        for (int i = 0; i < 3; i++) {
            System.out.println(currentThread().getName() + ":" + i);
            if (i == 1 && currentThread().getName().equals("m1"))
                throw new RuntimeException("Mistake from Machine");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        DeadWithException machine = new DeadWithException();
        machine.setName("m1");
        machine.start();
        machine.run();
        System.out.println("Is machine alive: " + machine.isAlive());
        System.out.println("main: end");
    }
}
